package com.atguigu.eduservice.controller;


import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.subject.OneSubject;
import com.atguigu.eduservice.service.EduSubjectService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Api(description="课程添加")
@CrossOrigin
@RestController
@RequestMapping("/eduservice/subject")
public class EduSubjectController {
    @Autowired
    private EduSubjectService service;
    //添加课程分类
    //获取上传过来的文件，把文件内容读出来
    @PostMapping("/addSubject")
    public R addSubject(MultipartFile multipartFile){
        //上传过来的文件

        service.saveSubject(multipartFile,service);

        return R.ok();
    }


    //课程分类列表功能  树形显示

    /**
     * id: 1,
*         label: 'Level one 1',
*         children: [{
*           id: 4,
*           label: 'Level two 1-1',
*           children: [{
*             id: 9,
*             label: 'Level three 1-1-1'
*           }, {
*             id: 10,
*             label: 'Level three 1-1-2'
*           }]
     * @return
     */
    //1.针对返回数据创建对应实体类
    //2.在两个实体类之间表示关系（一个一级分类有多个二级分类）
    @GetMapping("getAllSubject")
    public R getAllSubject(){
       List<OneSubject> list= service.getAllOneTwoSubject();

        return R.ok().data("list",list);
    }


}

